home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / e_to_l / fbuilder / delphi / demos / fltdemfm.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-15  |  3KB  |  127 lines

  1. unit Fltdemfm;
  2. interface
  3. uses
  4.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  5.   Forms, Dialogs, DBTables, DB, Grids, DBGrids, StdCtrls,
  6.   ExtCtrls, Buttons ,FiltrFrm,fbcomp,fbdbcomp;
  7.  
  8. type
  9.   TForm1 = class(TForm)
  10.     CustomerTable: TTable;
  11.     CustomerDataSource: TDataSource;
  12.     CustomerGrid: TDBGrid;
  13.     FilterPanel: TPanel;
  14.     CustomerTableCustNo: TFloatField;
  15.     CustomerTableCompany: TStringField;
  16.     CustomerTableAddr1: TStringField;
  17.     CustomerTableCity: TStringField;
  18.     CustomerTableState: TStringField;
  19.     CustomerTableZip: TStringField;
  20.     CustomerTableCountry: TStringField;
  21.     CustomerTablePhone: TStringField;
  22.     CustomerTableFAX: TStringField;
  23.     CustomerTableTaxRate: TFloatField;
  24.     CustomerTableContact: TStringField;
  25.     CustomerTableLastInvoiceDate: TDateTimeField;
  26.     ResultsPanel: TPanel;
  27.     OrdersDatasource: TDataSource;
  28.     OrdersGrid: TDBGrid;
  29.     Formula: TBitBtn;
  30.     OrdersTable: TTable;
  31.     OrdersTableOrderNo: TFloatField;
  32.     OrdersTableItemsTotal: TCurrencyField;
  33.     OrdersTableFreight: TCurrencyField;
  34.     OrdersTableAmountPaid: TCurrencyField;
  35.     OrdersTablePaymentMethod: TStringField;
  36.     OrdersTableCustNo: TFloatField;
  37.     CustomerFilter: TDSFilter;
  38.     DBExpression: TDBExpression;
  39.     BitBtn3: TBitBtn;
  40.     GroupBox1: TGroupBox;
  41.     FilterBtn: TBitBtn;
  42.     cbxApplyFilter: TCheckBox;
  43.     FilterLabel: TLabel;
  44.     procedure FormCreate(Sender: TObject);
  45.     procedure FilterBtnClick(Sender: TObject);
  46.     procedure FormulaClick(Sender: TObject);
  47.     procedure CustomerDataSourceDataChange(Sender: TObject; Field: TField);
  48.     procedure OrdersDatasourceDataChange(Sender: TObject; Field: TField);
  49.     procedure cbxApplyFilterClick(Sender: TObject);
  50.   private
  51.     { Private declarations }
  52.   public
  53.     { Public declarations }
  54.     Procedure UpdateResults;
  55.     Procedure RefreshDisplay;
  56.   end;
  57.  
  58. var
  59.   Form1: TForm1;
  60.  
  61.  
  62. implementation
  63.  
  64. {$R *.DFM}
  65.  
  66. uses DBExprFm;
  67.  
  68.  
  69. procedure TForm1.FormCreate(Sender: TObject);
  70. begin
  71.   CustomerTable.Active := True;
  72.   DBExpression.Database := CustomerTable.Database;
  73. end;
  74.  
  75.  
  76. procedure TForm1.FilterBtnClick(Sender: TObject);
  77. begin
  78.   if BuildDSExpression('Filter Expression',[vtBoolean],
  79.                         CustomerFilter,
  80.                         CustomerFilter.DataSource.Dataset) then
  81.   begin
  82.     RefreshDisplay;
  83.   end;
  84. end;
  85.  
  86. procedure TForm1.FormulaClick(Sender: TObject);
  87. begin
  88.   DBExpression.Database := CustomerTable.Database;
  89.   if BuildDBExpression('Database Expression Example',DBExpression) then
  90.      UpdateResults;
  91. end;
  92.  
  93. Procedure TForm1.UpdateResults;
  94. begin
  95.   if DBExpression.isNull then
  96.      ResultsPanel.Caption := ''
  97.    else
  98.      ResultsPanel.Caption := ' > '+DBExpression.AsString;
  99. end;
  100.  
  101. Procedure TForm1.RefreshDisplay;
  102. begin
  103.   FilterPanel.Caption := ' > ' + CustomerFilter.Formula;
  104.   CustomerFilter.Refresh;
  105.   CustomerGrid.Invalidate;
  106.   CustomerTable.First;
  107. end;
  108.  
  109.  
  110. procedure TForm1.CustomerDataSourceDataChange(Sender: TObject;Field: TField);
  111. begin
  112.  UpdateResults;
  113. end;
  114.  
  115. procedure TForm1.OrdersDatasourceDataChange(Sender: TObject;Field: TField);
  116. begin
  117.    UpdateResults;
  118. end;
  119.  
  120. procedure TForm1.cbxApplyFilterClick(Sender: TObject);
  121. begin
  122.    CustomerFilter.Active := cbxApplyFilter.Checked;
  123.    RefreshDisplay;
  124. end;
  125.  
  126. end.
  127.